/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.martinkrasa.hockeymanager.site;

import com.martinkrasa.hockeymanager.site.entity.Match;
import com.martinkrasa.hockeymanager.site.entity.Result;
import com.martinkrasa.hockeymanager.site.entity.Team;
import com.martinkrasa.hockeymanager.site.interfaces.MatchInterface;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 *
 * @author martin.krasa
 */
@Controller
public class IndexController {
    
    private static final Logger log = LogManager.getLogger();
    
    @RequestMapping("")
    public String index() {
        
        log.info("Viewing index website.");
        
        return "index";
    }    
    
    @RequestMapping("match")
    public String match(Map<String, Object> model) {
        
        log.info("Starting simulation of match.");
        
        Team home = new Team(1, "Domaci", 9, 7);
        model.put("home", home);
        
        Team away = new Team(1, "Hoste", 8, 8);
        
        Match match = MatchInterface.playMatch(new Match(home, away));
        model.put("match", match);
        
        Result result = MatchInterface.getResult(match);
        model.put("result", result);
        
        log.info("Simulation of match finished.");
        
        return "match";
    }    
}
